<template>
  <div class="record">
    <c-title :hide="false" :text="textChange"></c-title>
    <template v-if="this.$route.params.ind == 0">
      <div class="list" v-for="item in list" :key="item.id">
        <div class="list_l">{{ item.date }}前充值</div>
        <div class="list_r" v-if="item.return_balance && item.return_balance.card_package">
          充值金额:
          <span>{{ item.return_balance.card_package.monthly_rent }}</span>
        </div>
      </div>
    </template>
    <!-- 未已返佣金 -->
    <template v-if="this.$route.params.ind == 2">
      <div class="list" v-for="item in list" :key="item.id">
        <div class="list_l">
          <div class="list_day">{{ item.date }}前充值</div>
        </div>
        <div class="list_r">
          返还：
          <span>{{ item.balance }}</span>
        </div>
      </div>
    </template>
    <!-- 已返佣金 -->
    <template v-if="this.$route.params.ind == 1">
      <div class="list" v-for="item in list" :key="item.id">
        <div class="list_l">
          <div class="list_sn" v-if="item.recharge_notify">{{ item.recharge_notify.recharge_no }}</div>
          <div class="list_day">{{ item.date }}</div>
        </div>
        <div class="list_r">
          <span>{{ item.balance }}</span>
        </div>
      </div>
    </template>
  </div>
</template>
<script>
import { scrollMixin } from "utils/mixin";
export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      list: [],
      page: 1,
      total_page: 0,
      isLoadMore: true
    };
  },
  computed: {
    textChange() {
      let txt = "";
      if (this.$route.params.ind == 0) {
        txt = "剩余未充值期数";
      } else if (this.$route.params.ind == 1) {
        txt = "累计已返佣金";
      } else if (this.$route.params.ind == 2) {
        txt = "剩余未返佣金";
      }
      this.fun.setWXTitle(txt);
      return txt;
    }
  },
  activated() {
    this.getData();
  },
  methods: {
    getData() {
      // 剩余未充值期数,已返佣金
      let urlStr = [
        "plugin.phone-bill-recharge.frontend.return-balance-record.future",
        "plugin.phone-bill-recharge.frontend.return-balance-record.returned",
        "plugin.phone-bill-recharge.frontend.return-balance-record.future-periods"
      ];
      let json = {
        return_balance_id: this.$route.params.id
      };
      $http.get(urlStr[this.$route.params.ind], json, "加载中...").then(
        response => {
          if (response.result === 1) {
            this.isLoadMore = true;
            this.list = response.data.data;
            this.total_page = response.data.last_page;
            if (!this.total_page) {
              this.total_page = 0;
            }
          } else {
            this.$toast(response.msg);
          }
        },
        function(response) {
          console.log(response);
        }
      );
    },
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        let urlStr = [
          "plugin.phone-bill-recharge.frontend.return-balance-record.future",
          "plugin.phone-bill-recharge.frontend.return-balance-record.returned",
          "plugin.phone-bill-recharge.frontend.return-balance-record.future-periods"
        ];
        let json = {
          return_balance_id: this.$route.params.id,
          page:this.page
        };
        $http.post(urlStr[this.$route.params.ind], json, "加载中").then(
          response => {
            this.isLoadMore = true;
            if (res.result === 1) {
              this.list = this.list.concat(response.data.data); //数组拼接
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          },
        );
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.record {
  min-height: 100vh;
  background: #fff;
}
.list {
  display: flex;
  justify-content: space-between;
  margin: 0.5rem 0.75rem;
  padding: 1rem 0.75rem;
  .list_l {
    display: flex;
    flex-direction: column;
    text-align: left;
    .list_sn {
      margin-bottom: 0.25rem;
      font-size: 0.88rem;
    }
    .list_day {
      font-size: 0.75rem;
      font-weight: 400;
      color: #aaaab3;
    }
  }
  .list_r {
    font-size: 0.88rem;
    color: #aaaab3;
    span {
      color: #ff8924;
    }
  }
}
.list:first-child {
  margin-top: 0;
}
</style>
